/*
 * @Date: 2025-07-16 10:58:46
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-07-17 16:54:37
 * @FilePath: \corpus\src\pages\Message\index.tsx
 */
import hooks from './hooks';
import React from 'react';
import { ProList } from '@ant-design/pro-components';
import { Button, Space, Tag } from 'antd';
import { getMyViewApply } from '@/services/ant-design-pro/apply';
import { history } from '@umijs/max';
type GithubIssueItem = {
  url: string;
  id: number;
  number: number;
  title: string;
  labels: {
    name: string;
    color: string;
  }[];
  state: string;
  comments: number;
  created_at: string;
  updated_at: string;
  closed_at?: string;
};
const Message: React.FC = () => {
  // const {} = use;
  return (
    <>
      <ProList<GithubIssueItem>
        toolBarRender={() => {
          return [];
        }}
        search={{
          filterType: 'light',
        }}
        rowKey="name"
        request={async (params = {} as Record<string, any>) => {
          const msg = await getMyViewApply({
            ...params,
          });
          return {
            data: msg.data,
            // success 请返回 true，
            // 不然 table 会停止解析数据，即使有数据
            success: true,
            // 不传会使用 data 的长度，如果是分页一定要传
            total: msg.total,
          };
        }}
        pagination={{
          pageSize: 10,
        }}
        showActions="hover"
        metas={{
          title: {
            dataIndex: 'knowledgeName',
            title: '用户',
            search: false,
          },
          avatar: {
            dataIndex: 'avatar',
            search: false,
          },
          description: {
            dataIndex: 'submitTime',
            search: false,
            render: (_, record: any) => {
              return [
                <span key={1}>
                  {`${record.applyUserName}${record.applyName}--申请时间：${record.submitTime}`}
                  {}
                </span>,
              ];
            },
          },
          subTitle: {
            dataIndex: 'labels',
            render: (_, row) => {
              return (
                <Space size={0}>
                  {row.labels?.map((label: { name: string }) => (
                    <Tag color="blue" key={label.name}>
                      {label.name}
                    </Tag>
                  ))}
                </Space>
              );
            },
            search: false,
          },
          actions: {
            render: (text, row) => [
              <a
                onClick={() => {
                  history.push({ pathname: '/home' });
                }}
                target="_blank"
                rel="noopener noreferrer"
                key="view"
              >
                查看
              </a>,
            ],
            search: false,
          },
          status: {
            // 自己扩展的字段，主要用于筛选，不在列表中显示
            title: '状态',
            valueType: 'select',
            search: false,

            valueEnum: {
              all: { text: '全部', status: 'Default' },
              open: {
                text: '未解决',
                status: 'Error',
              },
              closed: {
                text: '已解决',
                status: 'Success',
              },
              processing: {
                text: '解决中',
                status: 'Processing',
              },
            },
          },
        }}
      />
    </>
  );
};
export default () => {
  return (
    <hooks.Provider>
      <Message />
    </hooks.Provider>
  );
};
